import { get } from '@/http/axios.js'
const actions = {
  // 获取所有产品
  getAllProduct(context, list) {
    get('/product/pageQuery', list).then(res => {
      let products=res.data.data.list
      for(let item of products) {
        item.number=0
      }
      context.commit('SET_PRODUCTS', products)
      return products
    })
  }, 
  // 获取所有产品分类
  getCategory(context, list) {
    get('/productCategory/pageQuery', list).then(res => {
      context.commit('SET_CATEGORYS', res.data.data.list)
      return res.data.data.list
    })
  },
}
const mutations = {
  SET_PRODUCTS(state, response) {
    state.products = response
  },
  SET_CATEGORYS(state, response) {
    state.categorys = response
  },
}
const state = {
  products:[],
  categorys:[],
}

export default {
  namespaced: true,
  state,
  actions,
  mutations,
}